package me.zhengjie.modules.account.factory.service.Impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.account.domain.AccountAc50;
import me.zhengjie.modules.account.domain.AccountAc51;
import me.zhengjie.modules.account.factory.entity.InterestRate;
import me.zhengjie.modules.account.factory.service.AccountComputer;
import me.zhengjie.modules.account.factory.service.AccountPrintService;
import me.zhengjie.modules.account.factory.vo.AnnualConversionTransverse;
import me.zhengjie.modules.account.mapper.*;
import me.zhengjie.modules.account.service.AccountAc50Service;
import me.zhengjie.modules.system.domain.DictDetail;
import me.zhengjie.modules.system.mapper.DictDetailMapper;
import me.zhengjie.tool.ListUtil;
import me.zhengjie.tool.MyMap;
import me.zhengjie.tool.NPETool;
import me.zhengjie.tool.ValidateUtil;
import me.zhengjie.vo.Constant;
import me.zhengjie.vo.StandardVO;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 打印账户表实现类
 */
@Service
@RequiredArgsConstructor
public class AccountPrintServiceImpl implements AccountPrintService {

    private final AccountComputer accountComputer;
    private final AccountAa03Mapper accountAa03Mapper;
    private final AccountAc50Mapper accountAc50Mapper;
    private final AccountAc51Mapper accountAc51Mapper;
    private final AccountAc08Mapper accountAc08Mapper;
    private final AccountAa02Mapper accountAa02Mapper;
    private final AccountAc50a5Mapper accountAc50a5Mapper;
    private final AccountCommonMapper accountCommonMapper;
    private final DictDetailMapper dictDetailMapper;



    @Override
    public MyMap printAccount(MyMap myMap) {
        myMap.remove("aab359");

        String aae140 = myMap.getAsString("aae140");
        String aac062 = myMap.getAsString("aac062");
        MyMap resultMap = new MyMap();


        List<Map> ac01andAc19List = accountCommonMapper.getAC01AndAc19(myMap);

        List<Map> ac08List = accountCommonMapper.queryAc08(myMap);
        List<MyMap> ac08MyMaps = ListUtil.list2MyMapList(ac08List);
        String zhaabb001;
        String zhaabb004;
        String maxAaz159;
        if (ValidateUtil.isNotEmpty(ac08MyMaps)) {
            maxAaz159 = ac08MyMaps.stream().max(Comparator.comparing(m -> m.getAsInteger("aae003"))).orElseGet(MyMap::new).getAsString("aaz159");
            // 查询ac02
            Map q = new HashMap();
            q.put("aaz159", maxAaz159);
            if (ValidateUtil.isEmpty(maxAaz159)) {
                throw new IllegalArgumentException("没有获取到最大缴费1参保关系id");
            }
            List<Map> ac02s = accountCommonMapper.queryAc01Ac02(q);

            q.put("aab001", ac02s.get(0).get("aab001"));
           List<Map> ab01s = accountCommonMapper.queryAb01Ab02(q);
            if (ValidateUtil.isNotEmpty(ab01s)) {
                zhaabb004 = ab01s.get(0).get("aab004").toString();
                zhaabb001 = ab01s.get(0).get("aab001").toString();
                ac01andAc19List.stream().forEach(m -> {
                    m.put("aab001", zhaabb001);
                    m.put("aae044", zhaabb004);
                });
            }
        }
        List<Map> ac51ListMap = new ArrayList<>();
        String aae206 = "";
        List<DictDetail> aac004 = dictDetailMapper.findByDictName("aac004");
        List<DictDetail> aac005 = dictDetailMapper.findByDictName("aac005");

        if (ValidateUtil.isNotEmpty(ac01andAc19List)) {
            if(!ValidateUtil.isEmpty(ac01andAc19List.get(0).get("aae206"))){
            aae206=  ac01andAc19List.get(0).get("aae206").toString().replaceAll("-","").substring(0,6);

            ac01andAc19List.get(0).put("aac030",ValidateUtil.isEmpty(ac01andAc19List.get(0).get("aac030"))?"":ac01andAc19List.get(0).get("aac030").toString().replaceAll("-","").substring(0,8)) ;
            ac01andAc19List.get(0).put("aac049",ValidateUtil.isEmpty(ac01andAc19List.get(0).get("aac049"))?"":ac01andAc19List.get(0).get("aac049").toString().replaceAll("-","").substring(0,6)) ;
            ac01andAc19List.get(0).put("aae206",ValidateUtil.isEmpty(ac01andAc19List.get(0).get("aae206"))?"":ac01andAc19List.get(0).get("aae206").toString().replaceAll("-","").substring(0,6)) ;
            ac01andAc19List.get(0).put("xb",aac004.stream().filter(m->m.getValue().equals(ac01andAc19List.get(0).get("aac004"))).collect(Collectors.toList()).get(0).getLabel()) ;//性别
            ac01andAc19List.get(0).put("mz",aac005.stream().filter(m->m.getValue().equals(ac01andAc19List.get(0).get("aac005"))).collect(Collectors.toList()).get(0).getLabel()) ;//民族

            }
        }
        if (ValidateUtil.isEmpty(aae206)) {
            throw new IllegalArgumentException("没有发现建账年月，请先维护建账年月");
        }
        myMap.put("aae206", aae206);
        List<MyMap> ac51ListMyMapList;
        if (aae140.equals(Constant.AAE140_110_QYZGJBYLBX)) {
            ac51ListMap = queryAccountInfo(myMap);
            ac51ListMyMapList = ListUtil.list2MyMapList(ac51ListMap);
        } else {
            ac51ListMap = queryAccountInfoJg(myMap);
            ac51ListMyMapList = ListUtil.list2MyMapList(ac51ListMap);

        }
        ac51ListMyMapList.stream().forEach(m -> {
            m.put("sphbbl", m.getAsBigDecimalNullToZero("aae819").multiply(new BigDecimal("100")));//社评比例
            m.put("pjgz", m.getAsBigDecimalNullToZero("aae797"));//平均工资
            m.put("jfjs", m.getAsBigDecimalNullToZero("aae180"));//缴费基数
            m.put("aae202", m.getAsBigDecimalNullToZero("aae202"));//缴费月数
            m.put("dnll", m.getAsBigDecimalNullToZero("baa054").multiply(new BigDecimal("100")));//当年利率
            m.put("lnll", m.getAsBigDecimalNullToZero("baa055").multiply(new BigDecimal("100")));//当年利率
            m.put("aaa041", m.getAsBigDecimalNullToZero("aaa043").multiply(new BigDecimal("100")));//单位划账户
            m.put("aaa043", m.getAsBigDecimalNullToZero("aaa045").multiply(new BigDecimal("100")));//个人划账户
            m.put("aae819", m.getAsBigDecimalNullToZero("aae819").multiply(new BigDecimal("100")));//社评划账
            m.put("aae001", m.getAsString("aae001"));//年度
            m.put("dwhz", m.getAsBigDecimalNullToZero("aae262"));//单位划账
            m.put("grhz", m.getAsBigDecimalNullToZero("aae264"));//个人划账
            m.put("sphz", m.getAsBigDecimalNullToZero("aae855"));//社评划账
            m.put("dwdnlx", m.getAsBigDecimalNullToZero("aae263"));//单位当年利息
            m.put("grdnlx", m.getAsBigDecimalNullToZero("aae265"));//个人当年利息
            m.put("spdnlx", m.getAsBigDecimalNullToZero("aae856"));//社评当年利息
            m.put("dwsnm", m.getAsBigDecimalNullToZero("aae849"));//单位上年末
            m.put("grsnm", m.getAsBigDecimalNullToZero("aae851"));//个人上年末
            m.put("spsnm", m.getAsBigDecimalNullToZero("aae853"));//社评上年末
            m.put("dwsnmlx", m.getAsBigDecimalNullToZero("aae259"));//单位上年末
            m.put("grsnmlx", m.getAsBigDecimalNullToZero("aae260"));//个人上年末
            m.put("spsnmlx", m.getAsBigDecimalNullToZero("aae854"));//社评上年末
            m.put("zje", m.getAsBigDecimalNullToZero("aae878"));//社评上年末
        });
        resultMap.put("baseInfo", ac01andAc19List);
        resultMap.put("accountInfo", ac51ListMyMapList.stream().sorted(Comparator.comparing(mp -> mp.getAsInteger("aae001").intValue())).collect(Collectors.toList()));

        System.out.println(JSON.toJSONString(resultMap));
        return resultMap;
    }


    /**
     * @param checkMap myMap
     * @return {@link Map }
     * @Description 个人帐户台账查询
     * @Author
     * @Date 2022/01/05
     */
    public List<Map> queryAccountInfo(MyMap checkMap) {
        List<Map> ac51Outs = new ArrayList<>();
        NPETool.isEmptyThrowException(checkMap.getAsString("aac001"), "人员编号！");
        //取账户信息

        //取账户信息
        QueryWrapper<AccountAc50> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("aaz159", checkMap.getAsString("aaz159"));
        queryWrapper.eq("aaa119", Constant.AAA119_11_QYZGJBYLBXGRZH);
        queryWrapper.eq("aae100", Constant.AAE100_1_YX);


        List<MyMap> ac50s = ListUtil.list2MyMapList(accountAc50Mapper.selectList(queryWrapper));//账户信息
        if (ValidateUtil.isEmpty(ac50s)) {//没有账户也可以修改，新增账户
            return ac51Outs;
        }
        List<String> aaz116s = ac50s.stream()
                .map(map -> map.getAsString("aaz116")) // 提取aaz116
                .collect(Collectors.toList()); // 收集成 List


        QueryWrapper<AccountAc51> queryWrapperac51 = new QueryWrapper<>();
        queryWrapperac51.eq("aaz159", checkMap.getAsString("aaz159"));
        queryWrapperac51.in("aaz116", aaz116s);

        List<Map<String, Object>> acMap51s = accountAc51Mapper.selectMaps(queryWrapperac51);//台账信息
        NPETool.isEmptyThrowException(acMap51s, "个人账户台账！");
        List<MyMap> ac51s = ListUtil.list2MyMapList(acMap51s);
        Map<Integer, List<MyMap>> ac51Map = ac51s.stream().collect(Collectors.groupingBy(myMap -> myMap.getAsInteger("aae001")));
        String aac001 = checkMap.getAsString("aac001");
        String aaz159 = ac50s.get(0).getAsString("aaz159");
        Map<Integer, List<AnnualConversionTransverse>> ywnd = accountComputer.produceAnnualBusinessControls(aaz159, aac001, 1980);

//        List<MyMap> aa02Info = GetCachedData.getAa02ByRedis("SP100", "2");


          Map query=  new HashMap<>();
        query.put("aaa021","2");
        query.put("baa010","SP100");
        List<MyMap> aa02Info = ListUtil.list2MyMapList(accountAa02Mapper.selectByMap(query));




        //2、组织利率信息

        Map<String, Map<Integer, List<InterestRate>>>    aa03Map = accountComputer.produceAnnualInterestRate(Constant.AAC062_1_RYXCB, 1980);


        Map<Integer, List<InterestRate>> toYearsOverInterestRate = aa03Map.get("OverInterest");
        Map<Integer, List<InterestRate>> toYearsCurrentInterestRate = aa03Map.get("CurrentInterest");
        checkMap.put("tyjrzhdy", "1");
        checkMap.put("zzzhdy", "1");//终止账户也需要查询打印
        checkMap.put("ynPc06", "1");
        List<Map> ac08s = accountCommonMapper.queryAc08(checkMap);//实缴信息
        List<MyMap> ac08MyMapsList;
        if (ValidateUtil.isEmpty(ac08s)) {
            ac08MyMapsList = new ArrayList<>();
        } else {
            ac08MyMapsList = ListUtil.list2MyMapList(ac08s);
        }
        Integer aae206 = checkMap.getAsInteger("aae206");
        List<MyMap> jzqLists = ac08MyMapsList.stream().filter(mm -> mm.getAsInteger("aae003").intValue() < aae206
                && !Constant.AAE793_9024_JZQJFYS.equals(mm.getAsString("aae793"))
                && !Constant.AAE793_9022_CJZHTSMX.equals(mm.getAsString("aae793"))).collect(Collectors.toList());
        BigDecimal jzq_aae202 = BigDecimal.ZERO;
        if (ValidateUtil.isNotEmpty(jzqLists)) {
            jzq_aae202 = jzqLists.stream().map(ma -> ma.getAsBigDecimal("aae202")).reduce(BigDecimal.ZERO, BigDecimal::add);
        }
        final int[] count = {0};
        BigDecimal finalJzq_aae20 = jzq_aae202;
        Integer aae001_max = ac51s.stream().max(Comparator.comparing(myMap -> myMap.getAsInteger("aae001"))).orElseGet(MyMap::new).getAsInteger("aae001");
        ac51Map.forEach((aae001, ac51list) -> {
            Map tempAc51Map = new HashMap();
            BigDecimal aae849 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae849")).reduce(BigDecimal.ZERO, BigDecimal::add); //截至上年末个人账户单位缴费部分划转累计本息
            BigDecimal aae259 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae259")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至上年末个人账户单位缴费部分划转本息在本年产生的利息
            BigDecimal aae262 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae262")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年单位缴费部分划入个人账户本金
            BigDecimal aae263 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae263")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年单位缴费部分划入个人账户本金所产生的利息
            BigDecimal aae850 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae850")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至本年末个人账户单位缴费部分划转累计本息
            BigDecimal aae851 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae851")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至上年末个人账户个人缴费部分划转累计本息
            BigDecimal aae260 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae260")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至上年末个人账户个人缴费部分划转本息在本年产生的利息
            BigDecimal aae264 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae264")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年个人缴费部分划入个人账户本金
            BigDecimal aae265 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae265")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年个人缴费部分划入个人账户本金所产生的利息
            BigDecimal aae852 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae852")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至本年末个人账户个人缴费部分划转累计本息
            BigDecimal aae853 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae853")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至上年末个人账户其他部分划转累计本息
            BigDecimal aae854 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae854")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至上年末个人账户其他部分划转本息在本年产生的利息
            BigDecimal aae855 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae855")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年其他部分划入个人账户本金
            BigDecimal aae856 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae856")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年其他部分划入个人账户本金所产生的利息
            BigDecimal aae857 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae857")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至本年末个人账户其他部分划转累计本息
            BigDecimal aae873 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae873")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年本金总和
            BigDecimal aae874 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae874")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年利息总和
            BigDecimal aae875 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae875")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年补缴历年本金
            BigDecimal aae876 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae876")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年补缴历年利息
            BigDecimal aae879 = aae262.add(aae263).add(aae264).add(aae265).add(aae855).add(aae856);//本年合计
//            BigDecimal aae878 = aae857.add(aae852).add(aae850);//截至本年末总额
            BigDecimal aae878 = aae849.add(aae259).add(aae851).add(aae260).add(aae853).add(aae854).add(aae262).add(aae263).add(aae264).add(aae265).add(aae855).add(aae856);

            tempAc51Map.put("aae849", aae849);//截至上年末个人账户单位缴费部分划转累计本息
            tempAc51Map.put("aae259", aae259);//截至上年末个人账户单位缴费部分划转本息在本年产生的利息
            tempAc51Map.put("aae262", aae262);//本年单位缴费部分划入个人账户本金
            tempAc51Map.put("aae263", aae263);//本年单位缴费部分划入个人账户本金所产生的利息
            tempAc51Map.put("aae850", aae850);//截至本年末个人账户单位缴费部分划转累计本息
            tempAc51Map.put("aae851", aae851);//截至上年末个人账户个人缴费部分划转累计本息
            tempAc51Map.put("aae260", aae260);//截至上年末个人账户个人缴费部分划转本息在本年产生的利息
            tempAc51Map.put("aae264", aae264);//本年个人缴费部分划入个人账户本金
            tempAc51Map.put("aae265", aae265);//本年个人缴费部分划入个人账户本金所产生的利息
            tempAc51Map.put("aae852", aae852);//截至本年末个人账户个人缴费部分划转累计本息
            tempAc51Map.put("aae853", aae853);//截至上年末个人账户其他部分划转累计本息
            tempAc51Map.put("aae854", aae854);//截至上年末个人账户其他部分划转本息在本年产生的利息
            tempAc51Map.put("aae855", aae855);//本年其他部分划入个人账户本金
            tempAc51Map.put("aae856", aae856);//本年其他部分划入个人账户本金所产生的利息
            tempAc51Map.put("aae857", aae857);//截至本年末个人账户其他部分划转累计本息
            tempAc51Map.put("aae873", aae873);//本年本金总和
            tempAc51Map.put("aae874", aae874);//本年利息总和
            tempAc51Map.put("aae875", aae875);//本年补缴历年本金
            tempAc51Map.put("aae876", aae876);//本年补缴历年利息
            tempAc51Map.put("aae878", aae878);//截至本年末总额
            tempAc51Map.put("aae879", aae879);//本年合计
            tempAc51Map.put("aae001", aae001);//年度
            //取台账列表参数：账户类型,手工录入标志,年度,年度月数,缴费基数,本年应缴月数,本年实缴月数,上年度省社平工资,社平划入比例,个人缴费比例,单位划拨比例,当年利率,历年利率
            String aaa513 = "";//账户类型
            BigDecimal aae202 = BigDecimal.ZERO;//实缴月数
            //  BigDecimal aae202_40 = BigDecimal.ZERO;//实缴月数 趸交
            BigDecimal aae819 = BigDecimal.ZERO;//社平划入比例
            BigDecimal baa054 = BigDecimal.ZERO;//当年利率
            BigDecimal baa055 = BigDecimal.ZERO;//历年利率
            BigDecimal aae180 = BigDecimal.ZERO;//缴费基数
            BigDecimal aaa045 = BigDecimal.ZERO;//个人缴费比例
            BigDecimal aaa043 = BigDecimal.ZERO;//单位划拨比例

            //通过AC08来判断是否是交叉年度
            AnnualConversionTransverse annua = ywnd.get(aae001).get(0);
            BigDecimal bae095 = annua.getBae095();
            BigDecimal aae201 = annua.getBae084();
            List<MyMap> aa02s = aa02Info.stream().filter(mm -> mm.getAsInteger("aae001").intValue() == (aae001.intValue() - 1)).collect(Collectors.toList());
            BigDecimal aae797 = BigDecimal.ZERO;
            if (ValidateUtil.isNotEmpty(aa02s)) {
                StandardVO standardVO1 = new StandardVO("aae041", "Integer", "desc");
                ListUtil.sorts(aa02s, standardVO1);
                aae797 = aa02s.get(0).getAsBigDecimal("aaa010");
            }
            //当前年度存在采集账户
            List<MyMap> checkEntyList = new ArrayList<>();
            List<MyMap> checkEntyList_0 = ac08MyMapsList.stream().filter(mm -> mm.getAsInteger("aae003") >= annua.getAae041()
                    && annua.getAae042() >= mm.getAsInteger("aae003")
                    && Constant.AAE793_9023_CJZHCF.equals(mm.getAsString("aae793"))).collect(Collectors.toList());

            List<MyMap> checkEntyList_1 = ac08MyMapsList.stream().filter(mm -> (mm.getAsInteger("aae003") / 100) == aae001
                    && Constant.AAE793_9022_CJZHTSMX.equals(mm.getAsString("aae793"))).collect(Collectors.toList());

            checkEntyList.addAll(checkEntyList_0);
            checkEntyList.addAll(checkEntyList_1);
            //当前年度不存在采集账户
            List<MyMap> notEntyList;
            if (aae001_max.intValue() == aae001.intValue()) {//趸缴处理
                notEntyList = ac08MyMapsList.stream().filter(mm -> mm.getAsInteger("aae003") >= annua.getAae041()
                        //&& annua.getAae042() >= mm.getAsInteger("aae003")
                        && !Constant.AAE793_9022_CJZHTSMX.equals(mm.getAsString("aae793"))
                        && !Constant.AAE793_9023_CJZHCF.equals(mm.getAsString("aae793"))
                        && !Constant.AAE793_9024_JZQJFYS.equals(mm.getAsString("aae793"))).collect(Collectors.toList());
            } else {
                notEntyList = ac08MyMapsList.stream().filter(mm -> mm.getAsInteger("aae003") >= annua.getAae041()
                        && annua.getAae042() >= mm.getAsInteger("aae003")
                        && !Constant.AAE793_9022_CJZHTSMX.equals(mm.getAsString("aae793"))
                        && !Constant.AAE793_9023_CJZHCF.equals(mm.getAsString("aae793"))
                        && !Constant.AAE793_9024_JZQJFYS.equals(mm.getAsString("aae793"))).collect(Collectors.toList());
            }

            if (ValidateUtil.isNotEmpty(checkEntyList) && ValidateUtil.isNotEmpty(notEntyList)) {//交叉年度
                aaa513 = Constant.AAA513_2_LZH;
                BigDecimal aae202_1 = checkEntyList.stream().map(ma -> ma.getAsBigDecimalNullToZero("aae202")).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal aae202_2 = notEntyList.stream().map(ma -> ma.getAsBigDecimalNullToZero("aae202")).reduce(BigDecimal.ZERO, BigDecimal::add);
                aae202 = aae202_1.add(aae202_2);
                BigDecimal cjaae180 = checkEntyList.stream().map(cjaae1800 -> cjaae1800.getAsBigDecimalNullToZero("aae180")).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal zcaae180 = notEntyList.stream().map(zcaae1800 -> zcaae1800.getAsBigDecimalNullToZero("aae180")).reduce(BigDecimal.ZERO, BigDecimal::add);
                aae180 = aae202.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : (cjaae180.add(zcaae180)).divide(aae202, 2, BigDecimal.ROUND_HALF_UP);
                List<MyMap> ac50a4MyMaps = new ArrayList<>();
                if (!ValidateUtil.isEmpty(ac50a4MyMaps)) {
                    MyMap ac50a4MyMap = ac50a4MyMaps.get(0);
                    aae819 = ac50a4MyMap.getAsBigDecimalNullToZero("baa514");
                    baa054 = ac50a4MyMap.getAsBigDecimalNullToZero("baa054");
                    baa055 = ac50a4MyMap.getAsBigDecimalNullToZero("baa055");
                    //aae180 = checkEntyList.get(0).getAsBigDecimalNullToZero("aae180");
                    aaa043 = checkEntyList.get(0).getAsBigDecimalNullToZero("aaa043");
                    aaa045 = checkEntyList.get(0).getAsBigDecimalNullToZero("aaa045");
                } else {
                    aae819 = BigDecimal.ZERO;
                    aae202 = checkEntyList.stream().map(ma -> ma.getAsBigDecimalNullToZero("aae202")).reduce(BigDecimal.ZERO, BigDecimal::add);
                    baa054 = toYearsCurrentInterestRate.get(aae001).stream().sorted(Comparator.comparing(InterestRate::getAae041).reversed()).collect(Collectors.toList()).get(0).getAaa031();
                    baa055 = toYearsOverInterestRate.get(aae001).stream().sorted(Comparator.comparing(InterestRate::getAae041).reversed()).collect(Collectors.toList()).get(0).getAaa031();
                    // aae180 = checkEntyList.get(0).getAsBigDecimalNullToZero("aae180");
                    aaa043 = checkEntyList.get(0).getAsBigDecimalNullToZero("aaa043");
                    aaa045 = checkEntyList.get(0).getAsBigDecimalNullToZero("aaa045");
                }

            } else if (ValidateUtil.isEmpty(checkEntyList) && ValidateUtil.isNotEmpty(notEntyList)) {//只存在正常账户
                aaa513 = Constant.AAA513_1_XZH;
                baa054 = toYearsCurrentInterestRate.get(aae001).stream().sorted(Comparator.comparing(InterestRate::getAae041).reversed()).collect(Collectors.toList()).get(0).getAaa031();
                baa055 = toYearsOverInterestRate.get(aae001).stream().sorted(Comparator.comparing(InterestRate::getAae041).reversed()).collect(Collectors.toList()).get(0).getAaa031();
                aae819 = BigDecimal.ZERO;
                //趸交的月数  因为补缴当年如果趸交了往后多年 个人账户表打印 缴费比例会被缩小
                //       aae202_40=  notEntyList.stream().filter(m -> Constant.AAA115_40_YJHYCXJF.equals(m.get("aaa115"))).collect(Collectors.toList()).stream().map(ma -> ma.getAsBigDecimal("aae202")).reduce(BigDecimal.ZERO, BigDecimal::add);
                //     aae202_40=  BigDecimal.ZERO.stripTrailingZeros();
                //趸交数据
                //      List<MyMap> aaa115_40 = notEntyList.stream().filter(m -> Constant.AAA115_40_YJHYCXJF.equals(m.get("aaa115"))).collect(Collectors.toList());
                //         aaa115_40 = new ArrayList<>();

                aae202 = notEntyList.stream().map(ma -> ma.getAsBigDecimal("aae202")).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal sumAa043 = BigDecimal.ZERO;
                BigDecimal sumAa045 = BigDecimal.ZERO;
                BigDecimal allaae180 = BigDecimal.ZERO;
                for (MyMap ac08Mymap : notEntyList) {
                    if (ac08Mymap.getAsInteger("aae202") > 0 || (ac08Mymap.getAsInteger("aae202") <= 0 &&
                            (Constant.AAA115_35_JFBLDZBJ.equals(ac08Mymap.getAsString("aaa115")) ||
                                    Constant.AAA115_21_JFBLDZTS.equals(ac08Mymap.getAsString("aaa115")))) ||
                            (ac08Mymap.getAsInteger("aae202") <= 0 && !Constant.AAA115_34_JFJSDZBJ.equals(ac08Mymap.getAsString("aaa115")) &&
                                    !Constant.AAA115_22_JFJSDZTS.equals(ac08Mymap.getAsString("aaa115"))
                                    && ac08Mymap.getAsBigDecimalNullToZero("aae180").compareTo(BigDecimal.ZERO) == 0)
                    ) {
                        sumAa043 = sumAa043.add(ac08Mymap.getAsBigDecimalNullToZero("aaa043").multiply(ac08Mymap.getAsBigDecimal("aae202").compareTo(BigDecimal.ZERO)>0?ac08Mymap.getAsBigDecimal("aae202"):BigDecimal.ONE));
                        sumAa045 = sumAa045.add(ac08Mymap.getAsBigDecimalNullToZero("aaa045").multiply(ac08Mymap.getAsBigDecimal("aae202").compareTo(BigDecimal.ZERO)>0?ac08Mymap.getAsBigDecimal("aae202"):BigDecimal.ONE));

                    }
                    if (ac08Mymap.getAsInteger("aae202") > 0 || (ac08Mymap.getAsInteger("aae202") <= 0 &&
                            (Constant.AAA115_34_JFJSDZBJ.equals(ac08Mymap.getAsString("aaa115")) ||
                                    Constant.AAA115_22_JFJSDZTS.equals(ac08Mymap.getAsString("aaa115")))) ||
                            (ac08Mymap.getAsInteger("aae202") <= 0 && !Constant.AAA115_35_JFBLDZBJ.equals(ac08Mymap.getAsString("aaa115")) &&
                                    !Constant.AAA115_21_JFBLDZTS.equals(ac08Mymap.getAsString("aaa115")) &&
                                    !Constant.AAA115_36_TYJRBJ.equals(ac08Mymap.getAsString("aaa115")) &&
                                    ac08Mymap.getAsBigDecimalNullToZero("aae180").compareTo(BigDecimal.ZERO) != 0)
                    ) {
                        if (ac08Mymap.getAsBigDecimalNullToZero("aae022").compareTo(BigDecimal.ZERO) != 0) {//老系统缓缴单位是多条，增加金额判断，防止基数多加
                            allaae180 = allaae180.add(ac08Mymap.getAsBigDecimalNullToZero("aae180"));
                        }
                    }
                }
                if (sumAa043.compareTo(BigDecimal.ZERO) > 0) {
                    if (aae202.compareTo(BigDecimal.ZERO) > 0) {
//                        if(aae202_40.compareTo(BigDecimal.ZERO) > 0){
//                            BigDecimal aaa0431 = aaa115_40.stream().map(ma -> ma.getAsBigDecimal("aaa043")).reduce(BigDecimal.ZERO, BigDecimal::add);
//                            aaa043 = (sumAa043.subtract(aaa0431)).divide((aae202.subtract(aae202_40)), 4, BigDecimal.ROUND_HALF_UP);
//                        }else{
                        aaa043 = sumAa043.divide(aae202, 4, BigDecimal.ROUND_HALF_UP);
//                        }

                    } else {
                        aaa043 = BigDecimal.ZERO;
                    }
                }
                if (sumAa045.compareTo(BigDecimal.ZERO) > 0) {
                    if (aae202.compareTo(BigDecimal.ZERO) > 0) {
//                        if(aae202_40.compareTo(BigDecimal.ZERO) > 0){
//                            BigDecimal aaa0451 = aaa115_40.stream().map(ma -> ma.getAsBigDecimal("aaa045")).reduce(BigDecimal.ZERO, BigDecimal::add);
//                            aaa045 = (sumAa045.subtract(aaa0451)).divide((aae202.subtract(aae202_40)), 4, BigDecimal.ROUND_HALF_UP);
//                        }else{
                        aaa045 = sumAa045.divide(aae202, 4, BigDecimal.ROUND_HALF_UP);
//                        }

                    } else {
                        aaa045 = BigDecimal.ZERO;
                    }
                }
                if (allaae180.compareTo(BigDecimal.ZERO) > 0) {
                    if (aae202.compareTo(BigDecimal.ZERO) > 0) {
                        aae180 = allaae180.divide(aae202, 2, BigDecimal.ROUND_HALF_UP);
                    } else {
                        aae180 = BigDecimal.ZERO;
                    }
                }
            } else {
                aaa513 = Constant.AAA513_1_XZH;
                baa054 = toYearsCurrentInterestRate.get(aae001).stream().sorted(Comparator.comparing(InterestRate::getAae041).reversed()).collect(Collectors.toList()).get(0).getAaa031();
                baa055 = toYearsOverInterestRate.get(aae001).stream().sorted(Comparator.comparing(InterestRate::getAae041).reversed()).collect(Collectors.toList()).get(0).getAaa031();
                aae819 = BigDecimal.ZERO;
            }
            String aae825 = "";//手工录入标志
            List<MyMap> aae825Ac51List = ac51list.stream().filter(myMap -> myMap.getAsString("aae825").equals(Constant.AAE825_1_S) &&
                    (myMap.getAsBigDecimalNullToZero("aae262").compareTo(BigDecimal.ZERO) > 0 ||
                            myMap.getAsBigDecimalNullToZero("aae264").compareTo(BigDecimal.ZERO) > 0 ||
                            myMap.getAsBigDecimalNullToZero("aae855").compareTo(BigDecimal.ZERO) > 0)).collect(Collectors.toList());

            if (ValidateUtil.isNotEmpty(aae825Ac51List)) {
                aae825 = Constant.AAE825_1_S;
            } else {
                aae825 = Constant.AAE825_0_F;
            }
            tempAc51Map.put("aaa513", aaa513);
            tempAc51Map.put("aae202", aae202);
            tempAc51Map.put("aae819", aae819);
            tempAc51Map.put("baa054", baa054);
            tempAc51Map.put("baa055", baa055);
            tempAc51Map.put("aae180", aae180);
            tempAc51Map.put("aaa045", aaa045);
            tempAc51Map.put("aaa043", aaa043);
            tempAc51Map.put("aae825", aae825);
            tempAc51Map.put("bae095", bae095);
            tempAc51Map.put("aae201", aae201);
            tempAc51Map.put("aae797", aae797);
            tempAc51Map.put("key", count[0]);
            tempAc51Map.put("jzq_aae202", finalJzq_aae20);
            count[0] = count[0] + 1;
            ac51Outs.add(tempAc51Map);
        });
        ac51Outs.sort(Comparator.comparingInt(ac51 -> Integer.valueOf(ac51.get("aae001").toString())));
        List<MyMap> jzqysList = ac08MyMapsList.stream().filter(mm -> Constant.AAE793_9024_JZQJFYS.equals(mm.getAsString("aae793"))).collect(Collectors.toList());
        Integer aae091 = 0;
        if (ValidateUtil.isNotEmpty(jzqysList)) {
            aae091 = jzqysList.get(0).getAsInteger("aae202");
        }
        for (Map map : ac51Outs) {
            MyMap myMap = new MyMap(map);
            map.put("aae091", aae091);
            aae091 = aae091 + (ValidateUtil.isEmpty(myMap.getAsString("aae202")) ? 0 : myMap.getAsInteger("aae202"));
        }
        return ac51Outs;
    }

    /**
     * @param checkMap myMap
     * @return {@link Map }
     * @Description 机关个人帐户台账查询
     * @Author jzy
     * @Date 2022/01/05
     */
    public List<Map> queryAccountInfoJg(MyMap checkMap) {
        List<Map> ac51Outs = new ArrayList<>();
        NPETool.isEmptyThrowException(checkMap.getAsString("aac001"), "人员编号！");
        //取账户信息
        checkMap.put("aaa119", Constant.AAA119_12_JGSYDWJBYLBXGRZH);
        QueryWrapper<AccountAc50> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("aaa119", Constant.AAA119_12_JGSYDWJBYLBXGRZH);
        queryWrapper.eq("aaz159", checkMap.getAsString("aaz159"));
        queryWrapper.eq("aae100", Constant.AAE100_1_YX);
        queryWrapper.eq("aac062", checkMap.getAsString("aac062"));


        List<MyMap> ac50s = ListUtil.list2MyMapList(accountAc50Mapper.selectList(queryWrapper));//账户信息
        if (ValidateUtil.isEmpty(ac50s)) {//没有账户也可以修改，新增账户
            return ac51Outs;
        }
        List<String> aaz116s = ac50s.stream()
                .map(map -> map.getAsString("aaz116")) // 提取aaz116
                .collect(Collectors.toList()); // 收集成 List

        QueryWrapper<AccountAc51> queryWrapperac51 = new QueryWrapper<>();
        queryWrapperac51.eq("aaz159", checkMap.getAsString("aaz159"));
        queryWrapperac51.in("aaz116", aaz116s);

        List<Map<String, Object>> acMap51s = accountAc51Mapper.selectMaps(queryWrapperac51);//台账信息
        NPETool.isEmptyThrowException(acMap51s, "个人账户台账！");
        List<MyMap> ac51s = ListUtil.list2MyMapList(acMap51s);
        Map<Integer, List<MyMap>> ac51Map = ac51s.stream().collect(Collectors.groupingBy(myMap -> myMap.getAsInteger("aae001")));
        String aac001 = checkMap.getAsString("aac001");
        String aaz159 = ac50s.get(0).getAsString("aaz159");
        Map<Integer, List<AnnualConversionTransverse>> ywnd = accountComputer.produceAnnualBusinessControls(aaz159, aac001, 1984);

        Map query=  new HashMap<>();
        query.put("aaa021","2");
        query.put("baa010","SP100");
        List<MyMap> aa02Info = ListUtil.list2MyMapList(accountAa02Mapper.selectByMap(query));


        //3、组织利率信息

        Map<String, Map<Integer, List<InterestRate>>>    aa03Map = accountComputer.produceAnnualInterestRate(checkMap.getAsString("aac062"), 1980);


        Map<Integer, List<InterestRate>> toYearsOverInterestRate = aa03Map.get("OverInterest");
        Map<Integer, List<InterestRate>> toYearsCurrentInterestRate = aa03Map.get("CurrentInterest");
        checkMap.put("tyjrzhdy", "1");
        checkMap.put("zzzhdy", "1");
        checkMap.put("aae820", checkMap.getAsString("aac062"));
        List<Map> ac08s = accountCommonMapper.queryAc08(checkMap);//实缴信息
        List<MyMap> ac08MyMapsList;
        if (ValidateUtil.isEmpty(ac08s)) {
            ac08MyMapsList = new ArrayList<>();
        } else {
            ac08MyMapsList = ListUtil.list2MyMapList(ac08s);
        }

        final int[] count = {0};
        Integer aae206 = checkMap.getAsInteger("aae206");
        Integer minAae003 = ac08MyMapsList.stream().map(map -> map.getAsInteger("aae003")).min(Integer::compareTo).orElse(0);
        if (aae206.intValue() > 201410 && minAae003.intValue() < aae206) {
            aae206 = minAae003;
        }
        Integer finalAae20 = aae206;
        List<MyMap> jzqLists = ac08MyMapsList.stream().filter(mm -> mm.getAsInteger("aae003").intValue() < finalAae20
                && !Constant.AAE793_9024_JZQJFYS.equals(mm.getAsString("aae793"))
        ).collect(Collectors.toList());
        BigDecimal jzq_aae202 = BigDecimal.ZERO;
        if (ValidateUtil.isNotEmpty(jzqLists)) {
            jzq_aae202 = jzqLists.stream().map(ma -> ma.getAsBigDecimal("aae202")).reduce(BigDecimal.ZERO, BigDecimal::add);
        }
        BigDecimal finalJzq_aae20 = jzq_aae202;
        ac51Map.forEach((aae001, ac51list) -> {
            Map tempAc51Map = new HashMap();
            BigDecimal aae849 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae849")).reduce(BigDecimal.ZERO, BigDecimal::add); //截至上年末个人账户单位缴费部分划转累计本息
            BigDecimal aae259 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae259")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至上年末个人账户单位缴费部分划转本息在本年产生的利息
            BigDecimal aae262 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae262")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年单位缴费部分划入个人账户本金
            BigDecimal aae263 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae263")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年单位缴费部分划入个人账户本金所产生的利息
            BigDecimal aae850 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae850")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至本年末个人账户单位缴费部分划转累计本息
            BigDecimal aae851 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae851")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至上年末个人账户个人缴费部分划转累计本息
            BigDecimal aae260 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae260")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至上年末个人账户个人缴费部分划转本息在本年产生的利息
            BigDecimal aae264 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae264")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年个人缴费部分划入个人账户本金
            BigDecimal aae265 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae265")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年个人缴费部分划入个人账户本金所产生的利息
            BigDecimal aae852 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae852")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至本年末个人账户个人缴费部分划转累计本息
            BigDecimal aae853 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae853")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至上年末个人账户其他部分划转累计本息
            BigDecimal aae854 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae854")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至上年末个人账户其他部分划转本息在本年产生的利息
            BigDecimal aae855 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae855")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年其他部分划入个人账户本金
            BigDecimal aae856 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae856")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年其他部分划入个人账户本金所产生的利息
            BigDecimal aae857 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae857")).reduce(BigDecimal.ZERO, BigDecimal::add);//截至本年末个人账户其他部分划转累计本息
            BigDecimal aae873 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae873")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年本金总和
            BigDecimal aae874 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae874")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年利息总和
            BigDecimal aae875 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae875")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年补缴历年本金
            BigDecimal aae876 = ac51list.stream().map(itemAc51Map -> itemAc51Map.getAsBigDecimalNullToZero("aae876")).reduce(BigDecimal.ZERO, BigDecimal::add);//本年补缴历年利息
            BigDecimal aae879 = aae262.add(aae263).add(aae264).add(aae265).add(aae855).add(aae856);//本年合计
//            BigDecimal aae878 = aae857.add(aae852).add(aae850);//截至本年末总额

            BigDecimal aae878 = aae849.add(aae259).add(aae851).add(aae260).add(aae853).add(aae854).add(aae262).add(aae263).add(aae264).add(aae265).add(aae855).add(aae856);


            tempAc51Map.put("aae849", aae849);//截至上年末个人账户单位缴费部分划转累计本息
            tempAc51Map.put("aae259", aae259);//截至上年末个人账户单位缴费部分划转本息在本年产生的利息
            tempAc51Map.put("aae262", aae262);//本年单位缴费部分划入个人账户本金
            tempAc51Map.put("aae263", aae263);//本年单位缴费部分划入个人账户本金所产生的利息
            tempAc51Map.put("aae850", aae850);//截至本年末个人账户单位缴费部分划转累计本息
            tempAc51Map.put("aae851", aae851);//截至上年末个人账户个人缴费部分划转累计本息
            tempAc51Map.put("aae260", aae260);//截至上年末个人账户个人缴费部分划转本息在本年产生的利息
            tempAc51Map.put("aae264", aae264);//本年个人缴费部分划入个人账户本金
            tempAc51Map.put("aae265", aae265);//本年个人缴费部分划入个人账户本金所产生的利息
            tempAc51Map.put("aae852", aae852);//截至本年末个人账户个人缴费部分划转累计本息
            tempAc51Map.put("aae853", aae853);//截至上年末个人账户其他部分划转累计本息
            tempAc51Map.put("aae854", aae854);//截至上年末个人账户其他部分划转本息在本年产生的利息
            tempAc51Map.put("aae855", aae855);//本年其他部分划入个人账户本金
            tempAc51Map.put("aae856", aae856);//本年其他部分划入个人账户本金所产生的利息
            tempAc51Map.put("aae857", aae857);//截至本年末个人账户其他部分划转累计本息
            tempAc51Map.put("aae873", aae873);//本年本金总和
            tempAc51Map.put("aae874", aae874);//本年利息总和
            tempAc51Map.put("aae875", aae875);//本年补缴历年本金
            tempAc51Map.put("aae876", aae876);//本年补缴历年利息
            tempAc51Map.put("aae878", aae878);//截至本年末总额
            tempAc51Map.put("aae879", aae879);//本年合计
            tempAc51Map.put("aae001", aae001);//年度
            //取台账列表参数：账户类型,手工录入标志,年度,年度月数,缴费基数,本年应缴月数,本年实缴月数,上年度省社平工资,社平划入比例,个人缴费比例,单位划拨比例,当年利率,历年利率
            String aaa513 = "";//账户类型
            BigDecimal aae202 = BigDecimal.ZERO;//实缴月数
            BigDecimal aae819 = BigDecimal.ZERO;//社平划入比例
            BigDecimal baa054 = BigDecimal.ZERO;//当年利率
            BigDecimal baa055 = BigDecimal.ZERO;//历年利率
            BigDecimal aae180 = BigDecimal.ZERO;//缴费基数
            BigDecimal aaa045 = BigDecimal.ZERO;//个人缴费比例
            BigDecimal aaa043 = BigDecimal.ZERO;//单位划拨比例

            //通过AC08来判断是否是交叉年度
            AnnualConversionTransverse annua = ywnd.get(aae001).get(0);
            BigDecimal bae095 = annua.getBae095();
            BigDecimal aae201 = annua.getBae084();
            List<MyMap> aa02s = aa02Info.stream().filter(mm -> mm.getAsInteger("aae001").intValue() == (aae001.intValue() - 1)).collect(Collectors.toList());
            BigDecimal aae797 = BigDecimal.ZERO;
            if (ValidateUtil.isNotEmpty(aa02s)) {
                StandardVO standardVO1 = new StandardVO("aae041", "Integer", "desc");
                ListUtil.sorts(aa02s, standardVO1);
                aae797 = aa02s.get(0).getAsBigDecimal("aaa010");
            }
            aaa513 = Constant.AAA513_1_XZH;
            baa054 = toYearsCurrentInterestRate.get(aae001).stream().sorted(Comparator.comparing(InterestRate::getAae041).reversed()).collect(Collectors.toList()).get(0).getAaa031();
            baa055 = toYearsOverInterestRate.get(aae001).stream().sorted(Comparator.comparing(InterestRate::getAae041).reversed()).collect(Collectors.toList()).get(0).getAaa031();
            aae819 = BigDecimal.ZERO;

            List<MyMap> checkEntyList_0 = ac08MyMapsList.stream().filter(mm -> mm.getAsInteger("aae003").intValue() >= annua.getAae041()
                    && annua.getAae042() >= mm.getAsInteger("aae003") && mm.getAsInteger("aae003").intValue() >= finalAae20).collect(Collectors.toList()
            );
            aae202 = checkEntyList_0.stream().map(ma -> ma.getAsBigDecimal("aae202")).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal sumAa043 = BigDecimal.ZERO;
            BigDecimal sumAa045 = BigDecimal.ZERO;
            BigDecimal allaae180 = BigDecimal.ZERO;
            for (MyMap ac08Mymap : checkEntyList_0) {
                if (ac08Mymap.getAsInteger("aae202") > 0 || (ac08Mymap.getAsInteger("aae202") <= 0 &&
                        (Constant.AAA115_35_JFBLDZBJ.equals(ac08Mymap.getAsString("aaa115")) ||
                                Constant.AAA115_21_JFBLDZTS.equals(ac08Mymap.getAsString("aaa115"))))) {
                    sumAa043 = sumAa043.add(ac08Mymap.getAsBigDecimalNullToZero("aaa043").multiply(ac08Mymap.getAsBigDecimal("aae202").compareTo(BigDecimal.ZERO)>0?ac08Mymap.getAsBigDecimal("aae202"):BigDecimal.ONE));
                    sumAa045 = sumAa045.add(ac08Mymap.getAsBigDecimalNullToZero("aaa045").multiply(ac08Mymap.getAsBigDecimal("aae202").compareTo(BigDecimal.ZERO)>0?ac08Mymap.getAsBigDecimal("aae202"):BigDecimal.ONE));

                }
                if (ac08Mymap.getAsInteger("aae202") > 0 || (ac08Mymap.getAsInteger("aae202") <= 0 &&
                        (Constant.AAA115_34_JFJSDZBJ.equals(ac08Mymap.getAsString("aaa115")) ||
                                Constant.AAA115_22_JFJSDZTS.equals(ac08Mymap.getAsString("aaa115")))) ||
                        (ac08Mymap.getAsInteger("aae202") <= 0 && Constant.AAE793_1061_ZR.equals(ac08Mymap.getAsString("aae793")))
                ) {
                    allaae180 = allaae180.add(ac08Mymap.getAsBigDecimalNullToZero("aae180"));
                }
            }
            if (sumAa043.compareTo(BigDecimal.ZERO) > 0) {

                aaa043 = aae202.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : sumAa043.divide(aae202, 4, BigDecimal.ROUND_HALF_UP);
            }
            if (sumAa045.compareTo(BigDecimal.ZERO) > 0) {
                aaa045 = aae202.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : sumAa045.divide(aae202, 4, BigDecimal.ROUND_HALF_UP);
            }
            if (allaae180.compareTo(BigDecimal.ZERO) > 0) {
                aae180 = aae202.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : allaae180.divide(aae202, 2, BigDecimal.ROUND_HALF_UP);
            }

            tempAc51Map.put("aaa513", aaa513);
            tempAc51Map.put("aae202", aae202);
            tempAc51Map.put("aae819", aae819);
            tempAc51Map.put("baa054", baa054);
            tempAc51Map.put("baa055", baa055);
            tempAc51Map.put("aae180", aae180);
            tempAc51Map.put("aaa045", aaa045);
            tempAc51Map.put("aaa043", aaa043);
            tempAc51Map.put("aae825", 0);
            tempAc51Map.put("bae095", bae095);
            tempAc51Map.put("aae201", aae201);
            tempAc51Map.put("aae797", aae797);
            tempAc51Map.put("key", count[0]);
            tempAc51Map.put("jzq_aae202", finalJzq_aae20);
            count[0] = count[0] + 1;
            ac51Outs.add(tempAc51Map);
        });
        ac51Outs.sort(Comparator.comparingInt(ac51 -> Integer.valueOf(ac51.get("aae001").toString())));
        List<MyMap> jzqysList = ac08MyMapsList.stream().filter(mm -> Constant.AAE793_9024_JZQJFYS.equals(mm.getAsString("aae793"))).collect(Collectors.toList());
        Integer aae091 = 0;
        if (ValidateUtil.isNotEmpty(jzqysList)) {
            aae091 = jzqysList.get(0).getAsInteger("aae202");
        }
        for (Map map : ac51Outs) {
            MyMap myMap = new MyMap(map);
            map.put("aae091", aae091);
            aae091 = aae091 + (ValidateUtil.isEmpty(myMap.getAsString("aae202")) ? 0 : myMap.getAsInteger("aae202"));
        }
        return ac51Outs;
    }

}
